package com.suray.wcs.web.system.controller;

import com.suray.basic.wcs.plc.entity.PlcLogDB;
import com.suray.basic.wcs.plc.service.impl.PlcLogServiceImpl;
import com.suray.commin.annotation.Log;
import com.suray.commin.core.controller.BaseController;
import com.suray.commin.core.controller.ResponseData;
import com.suray.commin.core.page.TableDataInfo;
import com.suray.commin.core.utils.ExcelUtil;
import com.suray.commin.enmus.BusinessType;
import com.suray.wcs.service.system.entity.InterfaceLogDB;
import com.suray.wcs.service.system.entity.OperationLogDB;
import com.suray.wcs.service.system.service.impl.InterfaceLogServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/plcLog")
@CrossOrigin(value = "*", allowCredentials = "true")
public class PlcLogController extends BaseController {

    @Autowired
    private PlcLogServiceImpl plcLogService;

    /**
     * 分页查询
     *
     * @param plcLogDB
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcLog:list')")
    @ApiOperation(value = "查询接口日志")
    @GetMapping(value = "/list")
    @ResponseBody
    public TableDataInfo list(PlcLogDB plcLogDB) {
        startPage();
        List<PlcLogDB> plcLogDBS = plcLogService.getPlcLogs(plcLogDB);
        return getDataTable(plcLogDBS);
    }

    @Log(title = "plc交互日志", method = "导出plc交互日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('plcLog:export')")
    @GetMapping("/export")
    public ResponseData export(PlcLogDB plcLogDB) {
        List<PlcLogDB> list = plcLogService.getPlcLogs(plcLogDB);
        ExcelUtil<PlcLogDB> util = new ExcelUtil<>(PlcLogDB.class);
        return util.exportExcel(list, "plc交互日志");
    }

    @PreAuthorize("@ss.hasPermi('plcLog:remove')")
    @DeleteMapping("/{plcLogIds}")
    public ResponseData remove(@PathVariable Long[] plcLogIds) {
        return toAjax(plcLogService.deletePlcLogByIds(plcLogIds));
    }

    @Log(title = "plc交互日志", method = "清空plc交互日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('plcLog:remove')")
    @DeleteMapping("/clean")
    public ResponseData clean() {
        plcLogService.cleanPlcLog();
        return ResponseData.success();
    }
}
